
package de.jmda.gen.java.impl;

import javax.validation.constraints.NotNull;

import de.jmda.gen.java.DeclaredElementGenerator;
import de.jmda.gen.java.DeclaredTypeGenerator;
import de.jmda.gen.java.TypeDeclarationGenerator;

public class DefaultTypeDeclarationGenerator
		extends AbstractDeclarationGenerator
		implements TypeDeclarationGenerator
{
	private @NotNull DeclaredTypeGenerator declaredTypeGenerator;

	public DefaultTypeDeclarationGenerator()
  {
		this(null);
  }

	/**
	 * @param declaredTypeGenerator
	 */
	public DefaultTypeDeclarationGenerator(DeclaredTypeGenerator generator)
  {
	  super();
	  
	  setDeclaredTypeGenerator(generator);

	  setComponentSeparator(" ");
  }

	/**
	 * @return {@link #declaredTypeGenerator}, if declared type generator is
	 *         <code>null</code> it will be lazily initialised because declared
	 *         type generator is mandatory.
	 *
	 * @see de.jmda.gen.java.TypeDeclarationGenerator#getDeclaredTypeGenerator()
	 */
	@Override
	@NotNull
  public DeclaredTypeGenerator getDeclaredTypeGenerator()
  {
	  return notNull(declaredTypeGenerator);
  }

	@Override
  public void setDeclaredTypeGenerator(@NotNull DeclaredTypeGenerator generator)
  {
		declaredTypeGenerator = notNull(generator);
  }

	@Override
	@NotNull
  public DeclaredElementGenerator getDeclaredElementGenerator()
  {
	  return getDeclaredTypeGenerator();
  }

	private DeclaredTypeGenerator notNull(DeclaredTypeGenerator generator)
  {
		if (generator == null)
		{
			generator = new DefaultDeclaredTypeGenerator();
		}

		return generator;
  }
}